<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/common.css" />
		<style type="text/css">
			.mui-bar-nav {
				border-bottom: 1px solid #eee;
			}
			
			.password {
				display: -webkit-box;
				display: -ms-flexbox;
				display: -webkit-flex;
				display: flex;
				background: #fff;
				border-bottom: 1px solid #eee;
				line-height: 40px;
				height: 40px;
				font-size: 12px;
				padding: 0 10px;
				color: #666;
			}
			
			.password>div:first-child {
				min-width: 60px;
			}
			
			.password input {
				padding: 0;
				margin: 0;
				height: 38px;
				border: none;
				width: 100%;
			}
			
			#footer {
				position: fixed;
				bottom: 0;
				width: 100%;
			}
			
			#footer>button {
				background: #bd212e;
				border-color: #bd212e;
				border-radius: 0;
				height: 40px;
				width: 100%;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left"></a>
			<h1 class="mui-title">个人信息</h1>
		</header>
		<div class="mui-content">
			<div class="password">
				<div>旧密码</div>
				<div><input class="oldPassword" type="password" placeholder="请输入旧密码" /></div>
			</div>
			<div class="password">
				<div>新密码</div>
				<div><input type="password" class="newPassword" placeholder="请输入新密码（6至20位数字和字母）" /></div>
			</div>
			<div class="password">
				<div>确认密码</div>
				<div><input type="password" class="successPassword" placeholder="请再次输入新密码" /></div>
			</div>
		</div>
		<div id="footer">
			<button type="button" class="mui-btn mui-btn-danger">确定</button>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init({swipeBack:true})
			var swith = false
			var passwords = /\d{6,20}/
			$("#footer").on("tap", function() {
				if(swith){
					return
				}
				swith = true
				if(common.replace($('.oldPassword').val()) == '') {
					common.toast('旧密码不能为空')
					return

				} else if(common.replace($('.newPassword').val()) == '') {
					common.toast('新密码不能为空')
					return
				} else if($('.newPassword').val() != $('.successPassword').val()) {
					common.toast('新密码不一致')
					return
				} else if(!passwords.test($('.newPassword').val())) {
					common.toast('请输入6至20位数字和字母')
					return
				}
				common.ajax('/userCenter/updatePassword', {
					oldPwd: $('.oldPassword').val(),
					newPwd: $('.newPassword').val()
				}, function(data) {
					swith = false
					if(data.code == 1) {
						common.toast('修改成功')
						$('input').blur()
						mui.back()
					} else {
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						} else {
							console.log(data)
						}
					}
				})
			})
		</script>
	</body>

</html>